package com.logistics.system.service.impl;

import java.util.List;

import com.logistics.common.core.constant.Constants;
import com.logistics.common.core.utils.DateUtils;
import com.logistics.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.logistics.system.mapper.WaybillsMapper;
import com.logistics.system.domain.Waybills;
import com.logistics.system.service.IWaybillsService;

/**
 * 运单Service业务层处理
 * 
 * @author logistics
 * @date 2024-06-23
 */
@Service
public class WaybillsServiceImpl implements IWaybillsService 
{
    @Autowired
    private WaybillsMapper waybillsMapper;

    /**
     * 查询运单
     * 
     * @param waybillId 运单主键
     * @return 运单
     */
    @Override
    public Waybills selectWaybillsByWaybillId(Long waybillId)
    {
        return waybillsMapper.selectWaybillsByWaybillId(waybillId);
    }

    /**
     * 查询运单列表
     * 
     * @param waybills 运单
     * @return 运单
     */
    @Override
    public List<Waybills> selectWaybillsList(Waybills waybills)
    {
        return waybillsMapper.selectWaybillsList(waybills);
    }

    /**
     * 新增运单
     * 
     * @param waybills 运单
     * @return 结果
     */
    @Override
    public int insertWaybills(Waybills waybills)
    {
        waybills.setCreatedTime(DateUtils.getNowDate());
        waybills.setCreatedBy(String.valueOf(SecurityUtils.getUserId()));
        waybills.setWaybillStatus(Constants.WAYBILL_STATUS_0);
        return waybillsMapper.insertWaybills(waybills);
    }

    /**
     * 修改运单
     * 
     * @param waybills 运单
     * @return 结果
     */
    @Override
    public int updateWaybills(Waybills waybills)
    {
        waybills.setUpdateBy(String.valueOf(SecurityUtils.getUserId()));
        waybills.setUpdateTime(DateUtils.getNowDate());
        return waybillsMapper.updateWaybills(waybills);
    }

    /**
     * 批量删除运单
     * 
     * @param waybillIds 需要删除的运单主键
     * @return 结果
     */
    @Override
    public int deleteWaybillsByWaybillIds(Long[] waybillIds)
    {
        return waybillsMapper.deleteWaybillsByWaybillIds(waybillIds);
    }

    /**
     * 删除运单信息
     * 
     * @param waybillId 运单主键
     * @return 结果
     */
    @Override
    public int deleteWaybillsByWaybillId(Long waybillId)
    {
        return waybillsMapper.deleteWaybillsByWaybillId(waybillId);
    }

    @Override
    public Long selectTransportPlanIdByWaybillId(Long waybillId) {
        return waybillsMapper.selectTransportPlanIdByWaybillIdd(waybillId);
    }
}
